package com.sihai.ehr.web.action.sign;

import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.sys.Organization;
import com.sihai.ehr.model.sys.User;
import com.sihai.ehr.service.UserService;
import com.sihai.ehr.utils.DateUtil;
import com.sihai.ehr.web.action.EHRAction;
import com.sihai.ehr.web.pojo.SearchFormPojo;
import org.apache.commons.lang.xwork.StringUtils;

import java.util.Calendar;

/**
 * author: wxn
 * since: 13-5-21 下午10:28
 */
public class SignBaseAction extends EHRAction {
    protected String startDateStr;
    protected String endDateStr;
    protected Long orgId;
    protected Long dutyId;

    protected Boolean search;
    protected SearchFormPojo searchFormPojo;

    protected int userType = 1;

    protected void init(){
        User user = getCurrentUser();
        if(user != null && user.getId() != null && user.getId() > 0){
            Organization organization = user.getWork().getOrganization();
            organizationId = organization.getTopOrganization() == null ? organization.getId() : organization.getTopOrganization().getId();
        }
        if(search != null && search.booleanValue()){
            searchFormPojo = new SearchFormPojo();
            if(StringUtils.isNotBlank(startDateStr)){
                searchFormPojo.setStartDate(DateUtil.createDate(startDateStr, "yyyy-MM-dd"));
            }
            if(StringUtils.isNotBlank(endDateStr)){
                searchFormPojo.setEndDate(DateUtil.createDate(endDateStr, "yyyy-MM-dd"));
            }
            if(orgId != null && orgId > 0){
                searchFormPojo.setOrgId(orgId);
            }
            if(dutyId != null && dutyId > 0){
                searchFormPojo.setDutyId(dutyId);
            }
        }
    }

    public void setEndDateStr(String endDateStr) {
        this.endDateStr = endDateStr;
    }

    public void setStartDateStr(String startDateStr) {
        this.startDateStr = startDateStr;
    }

    public String getStartDateStr() {
        return startDateStr;
    }

    public String getEndDateStr() {
        return endDateStr;
    }

    public Long getOrgId() {
        return orgId;
    }
    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }
    public Long getDutyId() {
        return dutyId;
    }
    public void setDutyId(Long dutyId) {
        this.dutyId = dutyId;
    }

    public void setSearch(Boolean search) {
        this.search = search;
    }

    public int getUserType() {
        return userType;
    }
}
